﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using CollegeShop.Api.DBUtility;//Please add references
namespace CollegeShop.Api.Infrastructure
{
	/// <summary>
	/// 数据访问类:t_salaryreport
	/// </summary>
	public partial class t_salaryreport
	{
		public t_salaryreport()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
        public bool Add(int college, CollegeShop.Api.Entity.t_salaryreport model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into t_salaryreport(");
			strSql.Append("Year,Month,UserName,BasicSalary,SaledMoney,RoyaltyRate,OnTimeRate,Bonus,RealSalary)");
			strSql.Append(" values (");
			strSql.Append("@Year,@Month,@UserName,@BasicSalary,@SaledMoney,@RoyaltyRate,@OnTimeRate,@Bonus,@RealSalary)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@Year", MySqlDbType.VarChar,4),
					new MySqlParameter("@Month", MySqlDbType.VarChar,2),
					new MySqlParameter("@UserName", MySqlDbType.VarChar,100),
					new MySqlParameter("@BasicSalary", MySqlDbType.Decimal,18),
					new MySqlParameter("@SaledMoney", MySqlDbType.Decimal,18),
					new MySqlParameter("@RoyaltyRate", MySqlDbType.Decimal,18),
					new MySqlParameter("@OnTimeRate", MySqlDbType.Decimal,18),
					new MySqlParameter("@Bonus", MySqlDbType.Decimal,18),
					new MySqlParameter("@RealSalary", MySqlDbType.Decimal,18)};
			parameters[0].Value = model.Year;
			parameters[1].Value = model.Month;
			parameters[2].Value = model.UserName;
			parameters[3].Value = model.BasicSalary;
			parameters[4].Value = model.SaledMoney;
			parameters[5].Value = model.RoyaltyRate;
			parameters[6].Value = model.OnTimeRate;
			parameters[7].Value = model.Bonus;
			parameters[8].Value = model.RealSalary;

            int rows = DbHelperMySQL.ExecuteSql(college, strSql.ToString(), parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
        public bool Update(int college, CollegeShop.Api.Entity.t_salaryreport model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update t_salaryreport set ");
			strSql.Append("Year=@Year,");
			strSql.Append("Month=@Month,");
			strSql.Append("UserName=@UserName,");
			strSql.Append("BasicSalary=@BasicSalary,");
			strSql.Append("SaledMoney=@SaledMoney,");
			strSql.Append("RoyaltyRate=@RoyaltyRate,");
			strSql.Append("OnTimeRate=@OnTimeRate,");
			strSql.Append("Bonus=@Bonus,");
			strSql.Append("RealSalary=@RealSalary");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@Year", MySqlDbType.VarChar,4),
					new MySqlParameter("@Month", MySqlDbType.VarChar,2),
					new MySqlParameter("@UserName", MySqlDbType.VarChar,100),
					new MySqlParameter("@BasicSalary", MySqlDbType.Decimal,18),
					new MySqlParameter("@SaledMoney", MySqlDbType.Decimal,18),
					new MySqlParameter("@RoyaltyRate", MySqlDbType.Decimal,18),
					new MySqlParameter("@OnTimeRate", MySqlDbType.Decimal,18),
					new MySqlParameter("@Bonus", MySqlDbType.Decimal,18),
					new MySqlParameter("@RealSalary", MySqlDbType.Decimal,18)};
			parameters[0].Value = model.Year;
			parameters[1].Value = model.Month;
			parameters[2].Value = model.UserName;
			parameters[3].Value = model.BasicSalary;
			parameters[4].Value = model.SaledMoney;
			parameters[5].Value = model.RoyaltyRate;
			parameters[6].Value = model.OnTimeRate;
			parameters[7].Value = model.Bonus;
			parameters[8].Value = model.RealSalary;

            int rows = DbHelperMySQL.ExecuteSql(college, strSql.ToString(), parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int college)
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from t_salaryreport ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

            int rows = DbHelperMySQL.ExecuteSql(college, strSql.ToString(), parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public CollegeShop.Api.Entity.t_salaryreport GetModel(int college)
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Year,Month,UserName,BasicSalary,SaledMoney,RoyaltyRate,OnTimeRate,Bonus,RealSalary from t_salaryreport ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

			CollegeShop.Api.Entity.t_salaryreport model=new CollegeShop.Api.Entity.t_salaryreport();
            DataSet ds = DbHelperMySQL.Query(college, strSql.ToString(), parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public CollegeShop.Api.Entity.t_salaryreport DataRowToModel(DataRow row)
		{
			CollegeShop.Api.Entity.t_salaryreport model=new CollegeShop.Api.Entity.t_salaryreport();
			if (row != null)
			{
				if(row["Year"]!=null)
				{
					model.Year=row["Year"].ToString();
				}
				if(row["Month"]!=null)
				{
					model.Month=row["Month"].ToString();
				}
				if(row["UserName"]!=null)
				{
					model.UserName=row["UserName"].ToString();
				}
				if(row["BasicSalary"]!=null && row["BasicSalary"].ToString()!="")
				{
					model.BasicSalary=decimal.Parse(row["BasicSalary"].ToString());
				}
				if(row["SaledMoney"]!=null && row["SaledMoney"].ToString()!="")
				{
					model.SaledMoney=decimal.Parse(row["SaledMoney"].ToString());
				}
				if(row["RoyaltyRate"]!=null && row["RoyaltyRate"].ToString()!="")
				{
					model.RoyaltyRate=decimal.Parse(row["RoyaltyRate"].ToString());
				}
				if(row["OnTimeRate"]!=null && row["OnTimeRate"].ToString()!="")
				{
					model.OnTimeRate=decimal.Parse(row["OnTimeRate"].ToString());
				}
				if(row["Bonus"]!=null && row["Bonus"].ToString()!="")
				{
					model.Bonus=decimal.Parse(row["Bonus"].ToString());
				}
				if(row["RealSalary"]!=null && row["RealSalary"].ToString()!="")
				{
					model.RealSalary=decimal.Parse(row["RealSalary"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
        public DataSet GetList(int college, string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Year,Month,UserName,BasicSalary,SaledMoney,RoyaltyRate,OnTimeRate,Bonus,RealSalary ");
			strSql.Append(" FROM t_salaryreport ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            return DbHelperMySQL.Query(college, strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
        public int GetRecordCount(int college, string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM t_salaryreport ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            object obj = DbHelperMySQL.GetSingle(college, strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
        public DataSet GetListByPage(int college, string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from t_salaryreport T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperMySQL.Query(college, strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "t_salaryreport";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

